<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta name="HandheldFriendly" content="True"/>
        <meta name="MobileOptimized" content="320"/>
        <meta name="format-detection" content="telephone=no"/>
        <meta name="apple-mobile-web-app-capable" content="yes" />
        <meta name="apple-mobile-web-app-status-bar-style" content="black" />
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
        <meta name="sharecontent"
        data-msg-img=""
        data-msg-title=""
        data-msg-content=""
        data-msg-callBack=""
        data-line-img=""
        data-line-title=""
        data-line-callBack="" />
        <title>华西证券股票专家</title>

        <link rel="stylesheet" type="text/css" href="css/mcmurphy.min.css"/>
        <script src="../cordova/cordova.js"></script>
        
        <script>
            function showToast(msg, duration) {  
                duration = isNaN(duration) ? 3000 : duration;  
                var m = document.createElement('div');  
                m.innerHTML = msg;  
                m.style.cssText = "width:50%; min-width:150px; background:#000; opacity:0.8; height:40px; color:#fff; line-height:40px; text-align:center; border-radius:3px; position:fixed; bottom:30px; left:25%; z-index:999999; font-weight:normal;";  
                document.body.appendChild(m);  
                setTimeout(function() {  
                    var d = 0.5;  
                    m.style.webkitTransition = '-webkit-transform ' + d  
                            + 's ease-in, opacity ' + d + 's ease-in';  
                    m.style.opacity = '0';  
                    setTimeout(function() {  
                        document.body.removeChild(m)  
                    }, d * 1000);  
                }, duration);  
            }

            function exitApp(){  
                navigator.app.exitApp();  
            }  

            function eventBackButton(){
          　　showToast("再按一次退出应用程序", 3000);
              document.removeEventListener("backbutton", eventBackButton, false);
              document.addEventListener("backbutton", exitApp, false);
              //3秒后重新注册
              var intervalID = window.setInterval(function() {
              　　window.clearInterval(intervalID);
                  document.removeEventListener("backbutton", exitApp, false); 
              　　document.addEventListener("backbutton", eventBackButton, false); //返回键
              },3000);
          　}

            function loadApp() {
                cordova.exec.setJsToNativeBridgeMode(cordova.exec.jsToNativeModes.XHR_NO_PAYLOAD);

                document.addEventListener("backbutton", eventBackButton, false);
            }
            
            document.addEventListener("deviceready", loadApp, false);


            /*=================================================================
              对外暴露的接口
            =================================================================*/
            var Observer = {
                addSubscriber: function (callback) {
                    this.subscribers[this.subscribers.length] = callback;
                },
                removeSubscriber: function (callback) {
                    for (var i = 0; i < this.subscribers.length; i++) {
                        if (this.subscribers[i] === callback) {
                            delete (this.subscribers[i]);
                        }
                    }
                },
                publish: function (what) {
                    for (var i = 0; i < this.subscribers.length; i++) {
                        if (typeof this.subscribers[i] === 'function') {
                            this.subscribers[i](what);
                        }
                    }
                },
                make: function (o) { 
                    for (var i in this) {
                        o[i] = this[i];
                        o.subscribers = [];
                    }
                }
            };

            window.Receiver = {
                receive: function (param) {
                    this.publish(param);
                }
            };

            Observer.make(window.Receiver);

            function rechargeCallBack(data){
                try{
                   if(typeof data === "string"){
                      data = eval("("+data+")");
                   }
                   window.Receiver.receive(data);
                }catch (e){
                    console.error(e);
                }
            }

        </script>
    </head>
    <body>
        <script src="main.js"></script>
    </body>
</html>